
import { Controller, Get, Post, Body,  UseFilters, HttpException, HttpStatus } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UsersService } from './users.service';
import { User } from './interfaces/user.interface';
import { HttpExceptionFilter } from '../http-exception.filter';

@Controller('users')
export class UsersController {
  constructor(private usersService: UsersService) {}

  @Post()
  async create(@Body() createUserDto: CreateUserDto) {
    return this.usersService.create(createUserDto);
  }

  @Get()
  @UseFilters(new HttpExceptionFilter()) // 绑定异常处理过滤器
  async findAll(): Promise<User[]> {
    return this.usersService.findAll();
    // throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
  }
}
